package com.ellricky.baselib.ui

import android.app.Activity
import android.content.Intent
import android.view.View
import android.widget.AdapterView
import com.andr.common.http.callback.BaseCallback
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.mvp.BasePresenter
import com.andr.common.util.ToastUtil
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.adapter.SelectActiveAdapter
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.entity.new.ClueActive
import com.ellricky.baselib.ui.base.BaseRefreshActivity
import com.ellricky.baselib.util.NewEBaseCallback
import com.ellricky.baselib.util.NewEListCallback

class SelectActiveActivity : BaseRefreshActivity<Void, BasePresenter<Void>, ClueActive>() {

    override fun initUIView() {
        super.initUIView()
        mTvTitle.text = "选择活动"
    }

    override fun getResponseCallback(): BaseCallback? {
        return null
    }

    override fun initParamMap() {
        super.initParamMap()
        paramMap["action"] = "saleActivityList"
        paramMap["school_id"] = LocalCacheUtil.getSchoolId()
        paramMap["eid"] = LocalCacheUtil.getUid()
    }

    override fun getResponseCallback2(): NewEBaseCallback {
        return object : NewEListCallback<ClueActive>(this) {
            override fun onSuccess(data: MutableList<ClueActive>?, msg: String?) {
                dataSource = data
                rvView.onLoadFinish(dataSource, refresh)
            }
        }
    }

    override fun onItemClick(adapterView: AdapterView<*>?, view: View?, position: Int, l: Long) {
        super.onItemClick(adapterView, view, position, l)
        val id = adapter[position].activity_id
        val name = adapter[position].activity_name
        ToastUtil.show(this, "已选择${name}")
        setResult(Activity.RESULT_OK, Intent().apply {
            putExtra(BaseConstant.KEY_ID, id)
            putExtra(BaseConstant.KEY_NAME, name)
        })
        finish()
    }

    override fun getRvAdapter(): BaseRecyclerAdapter<ClueActive> {
        return SelectActiveAdapter()
    }

    override fun getUrlPath(): String {
        return ""
    }
}